<template>
  <Form ref="refForm" :model="model" @submit-success="onOk">
    <FormItem field="name" title="名称" required>
      <Input v-model="model.name"/>
    </FormItem>
    <FormItem field="type" title="类型" required>
      <ees-enum clazz="OrgType" v-model="model.type"/>
    </FormItem>
    <FormItem field="fullName" title="全名">
      <Input v-model="model.fullName"/>
    </FormItem>
    <FormItem field="enName" title="英文名">
      <Input v-model="model.enName"/>
    </FormItem>
    <FormItem field="enFullName" title="英文全名">
      <Input v-model="model.enFullName"/>
    </FormItem>
    <template #op>
      <Button @click="Modal.close">取消</Button>
      <Button type="primary" html-type="submit" :loading="loading">保存</Button>
    </template>
  </Form>
</template>

<script setup>
import {Message, Form, FormItem, Input, Button, Modal} from "@idmy/ui";
import {useLoading} from "@idmy/core";
import {reactive} from "vue";
import {createOrUpdateOrg} from "./services";

const props = defineProps({modal: Object})

const model = reactive(props.model ?? {})

const [onOk, loading] = useLoading(async () => {
  await createOrUpdateOrg(model)
  Message.success('保存成功')
  Modal.ok()
})

</script>
<style scoped>
</style>
